{
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "!pip install mem0ai langchain_openai langchain_core python-dotenv -q"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "fGxGikIaTM-K",
        "outputId": "eec28183-2e6c-44ae-aee6-e972d6a9d735"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.4/50.4 kB\u001b[0m \u001b[31m3.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.2/73.2 kB\u001b[0m \u001b[31m4.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.7/49.7 kB\u001b[0m \u001b[31m3.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m404.4/404.4 kB\u001b[0m \u001b[31m12.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m47.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m294.6/294.6 kB\u001b[0m \u001b[31m17.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m296.6/296.6 kB\u001b[0m \u001b[31m18.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m383.7/383.7 kB\u001b[0m \u001b[31m24.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m54.4/54.4 kB\u001b[0m \u001b[31m3.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m266.4/266.4 kB\u001b[0m \u001b[31m17.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m49.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.4/2.4 MB\u001b[0m \u001b[31m65.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.8/5.8 MB\u001b[0m \u001b[31m77.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m76.4/76.4 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m78.0/78.0 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m325.2/325.2 kB\u001b[0m \u001b[31m20.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m43.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m141.9/141.9 kB\u001b[0m \u001b[31m8.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m54.5/54.5 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.5/57.5 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m3.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m316.6/316.6 kB\u001b[0m \u001b[31m19.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m3.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
            "google-ai-generativelanguage 0.6.6 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 5.28.2 which is incompatible.\n",
            "google-cloud-datastore 2.19.0 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 5.28.2 which is incompatible.\n",
            "google-cloud-firestore 2.16.1 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 5.28.2 which is incompatible.\n",
            "tensorboard 2.17.0 requires protobuf!=4.24.0,<5.0.0,>=3.19.6, but you have protobuf 5.28.2 which is incompatible.\n",
            "tensorflow 2.17.0 requires protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3, but you have protobuf 5.28.2 which is incompatible.\n",
            "tensorflow-metadata 1.16.0 requires protobuf<4.21,>=3.20.3; python_version < \"3.11\", but you have protobuf 5.28.2 which is incompatible.\u001b[0m\u001b[31m\n",
            "\u001b[0m"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mjQOHWnuTHZm"
      },
      "source": [
        "Store OPENAI_API_KEY in .env"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2lSzUsXwTHZr",
        "outputId": "99630519-af83-4b23-a5d6-913d6274b1c9"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "False"
            ]
          },
          "metadata": {},
          "execution_count": 4
        }
      ],
      "source": [
        "import dotenv\n",
        "dotenv.load_dotenv()"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from google.colab import userdata\n",
        "import os\n",
        "os.environ['OPENAI_API_KEY'] = userdata.get('OPENAI_API_KEY')"
      ],
      "metadata": {
        "id": "j0LZUQfGVnsv"
      },
      "execution_count": 10,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "id": "JbqpCS26THZv"
      },
      "outputs": [],
      "source": [
        "from mem0 import Memory\n",
        "from langchain_openai import ChatOpenAI\n",
        "from langchain_core.messages import AIMessage, HumanMessage, SystemMessage"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "wP13KuaqTHZv"
      },
      "outputs": [],
      "source": [
        "custom_prompt = \"\"\"\n",
        "Please only extract entities containing patient health information, appointment details, and user information.\n",
        "Here are some few shot examples:\n",
        "\n",
        "Input: Hi.\n",
        "Output: {{\"facts\" : []}}\n",
        "\n",
        "Input: The weather is nice today.\n",
        "Output: {{\"facts\" : []}}\n",
        "\n",
        "Input: I have a headache and would like to schedule an appointment.\n",
        "Output: {{\"facts\" : [\"Patient reports headache\", \"Wants to schedule an appointment\"]}}\n",
        "\n",
        "Input: My name is Jane Smith, and I need to reschedule my appointment for next Tuesday.\n",
        "Output: {{\"facts\" : [\"Patient name: Jane Smith\", \"Wants to reschedule appointment\", \"Original appointment: next Tuesday\"]}}\n",
        "\n",
        "Input: I have diabetes and my blood sugar is high.\n",
        "Output: {{\"facts\" : [\"Patient has diabetes\", \"Reports high blood sugar\"]}}\n",
        "\n",
        "Return the facts and patient information in a json format as shown above.\n",
        "\"\"\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "id": "NIjw8ZdKTHZw"
      },
      "outputs": [],
      "source": [
        "config = {\n",
        "    \"llm\": {\n",
        "        \"provider\": \"openai\",\n",
        "        \"config\": {\n",
        "            \"model\": \"gpt-4o\",\n",
        "            \"temperature\": 0.1,\n",
        "            \"max_tokens\": 2000,\n",
        "        }\n",
        "    },\n",
        "    \"embedder\": {\n",
        "        \"provider\": \"openai\",\n",
        "        \"config\": {\n",
        "            \"model\": \"text-embedding-3-large\"\n",
        "        }\n",
        "    },\n",
        "    \"vector_store\": {\n",
        "        \"provider\": \"qdrant\",\n",
        "        \"config\": {\n",
        "            \"collection_name\": \"test-123\",\n",
        "            \"embedding_model_dims\": 3072,\n",
        "        }\n",
        "    },\n",
        "    \"custom_prompt\": custom_prompt,\n",
        "    \"version\": \"v1.1\",\n",
        "}"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "id": "J-WLLyG5THZw"
      },
      "outputs": [],
      "source": [
        "class AIHealthcareSupport:\n",
        "    def __init__(self, config):\n",
        "        \"\"\"\n",
        "        Initialize the AI Healthcare Support with Memory Configuration and Langchain OpenAI Chat Model.\n",
        "\n",
        "        :param config: Configuration for memory and model settings.\n",
        "        \"\"\"\n",
        "        self.memory = Memory.from_config(config)\n",
        "        self.app_id = \"app-1\"\n",
        "        self.model = ChatOpenAI(model=\"gpt-4o\")\n",
        "\n",
        "    def ask(self, question, user_id=None):\n",
        "        \"\"\"\n",
        "        Ask a question to the AI and store the relevant facts in memory.\n",
        "\n",
        "        :param question: The question to ask the AI.\n",
        "        :param user_id: Optional user ID to associate with the memory.\n",
        "        :return: Response from the AI along with the original question.\n",
        "        \"\"\"\n",
        "        # Retrieve relevant memories using the search_memory method\n",
        "        memories = self.search_memory(question, user_id=user_id)\n",
        "\n",
        "        context = \"Relevant information from previous conversations:\\n\"\n",
        "        if memories['results']:\n",
        "            for memory in memories['results']:\n",
        "                context += f\" - {memory['memory']}\\n\"\n",
        "        print(context)\n",
        "\n",
        "        messages = [\n",
        "            SystemMessage(content=f\"\"\"You are a helpful healthcare support assistant. Use the provided context to personalize your responses and remember user health information and past interactions. {context}\"\"\"),\n",
        "            HumanMessage(content=question)\n",
        "        ]\n",
        "\n",
        "        response = self.model.invoke(messages)\n",
        "\n",
        "        # Store the interaction in memory\n",
        "        self.add_memory(question, response.content, user_id=user_id)\n",
        "        return {\"messages\": [response.content]}\n",
        "\n",
        "    def add_memory(self, question, response, user_id=None):\n",
        "        \"\"\"\n",
        "        Add a memory entry to the memory store.\n",
        "\n",
        "        :param question: The question that was asked by the user.\n",
        "        :param response: The response generated by the AI.\n",
        "        :param user_id: Optional user ID to associate with the memory.\n",
        "        \"\"\"\n",
        "        self.memory.add(f\"User: {question}\\nAssistant: {response}\", user_id=user_id, metadata={\"app_id\": self.app_id})\n",
        "\n",
        "    def get_memories(self, user_id=None):\n",
        "        \"\"\"\n",
        "        Retrieve all memories associated with the given user ID.\n",
        "\n",
        "        :param user_id: Optional user ID to filter memories.\n",
        "        :return: List of memories.\n",
        "        \"\"\"\n",
        "        return self.memory.get_all(user_id=user_id)\n",
        "\n",
        "    def search_memory(self, query, user_id=None):\n",
        "        \"\"\"\n",
        "        Search for memories related to the given query and user ID.\n",
        "\n",
        "        :param query: The query to search for in the memories.\n",
        "        :param user_id: Optional user ID to filter memories.\n",
        "        :return: List of relevant memories.\n",
        "        \"\"\"\n",
        "        related_memories = self.memory.search(query, user_id=user_id)\n",
        "        return related_memories"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "id": "tj83O0BlTHZx"
      },
      "outputs": [],
      "source": [
        "# Initialize the AIHealthcareSupport bot\n",
        "ai_support = AIHealthcareSupport(config)\n",
        "# User ID for interaction\n",
        "user_id = \"James\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "OgiATvOhTHZx",
        "outputId": "17033c04-96a1-40d0-c836-c6c98f215053"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Interacting with AI Healthcare Support:\n",
            "\n",
            "Relevant information from previous conversations:\n",
            "\n",
            "User: I have a family history of diabetes; how can I reduce my risk?\n",
            "AI: Reducing your risk of developing diabetes, especially with a family history, involves making some lifestyle changes and monitoring your health. Here are a few steps you can take:\n",
            "\n",
            "1. **Maintain a Healthy Weight:** Achieving and maintaining a healthy weight can significantly reduce your risk. Even a small amount of weight loss can have a positive impact.\n",
            "\n",
            "2. **Eat a Balanced Diet:** Focus on a diet rich in whole foods, including plenty of vegetables, fruits, whole grains, and lean proteins. Try to limit processed foods, added sugars, and unhealthy fats.\n",
            "\n",
            "3. **Stay Active:** Aim for at least 150 minutes of moderate aerobic activity, such as brisk walking, or 75 minutes of vigorous activity, such as running, each week. Also, include strength training exercises twice a week.\n",
            "\n",
            "4. **Regular Check-Ups:** Keep up with regular health check-ups to monitor your blood sugar levels and overall health. Early detection can help manage and mitigate potential issues.\n",
            "\n",
            "5. **Quit Smoking:** If you smoke, seek resources to help you quit. Smoking increases the risk of diabetes and other health issues.\n",
            "\n",
            "6. **Limit Alcohol Consumption:** Drink alcohol in moderation, if at all, as excessive intake can increase the risk of diabetes.\n",
            "\n",
            "7. **Stay Hydrated:** Drink plenty of water and limit sugary drinks.\n",
            "\n",
            "8. **Manage Stress:** Chronic stress can affect your blood sugar levels. Consider stress-reduction techniques such as yoga, meditation, or deep breathing exercises.\n",
            "\n",
            "If you have specific concerns or need personalized advice, it's always a good idea to consult with a healthcare professional. They can provide guidance tailored to your situation and health needs.\n",
            "\n",
            "Relevant information from previous conversations:\n",
            " - Wants to know how to reduce risk of diabetes\n",
            " - Patient has a family history of diabetes\n",
            "\n",
            "User: Can you recommend any specific dietary changes?\n",
            "AI: To help reduce your risk of diabetes, especially considering your family history, here are some dietary changes you might consider:\n",
            "\n",
            "1. **Increase Fiber Intake**: Include more fruits, vegetables, whole grains, and legumes in your diet. Foods high in fiber can help control blood sugar levels.\n",
            "\n",
            "2. **Choose Whole Grains**: Opt for whole grain products like brown rice, whole wheat bread, and oatmeal instead of their refined counterparts.\n",
            "\n",
            "3. **Limit Sugar and Refined Carbs**: Try to cut down on sugary drinks, sweets, and foods made with white flour. These can cause spikes in blood sugar.\n",
            "\n",
            "4. **Healthy Fats**: Incorporate healthy fats from sources like nuts, seeds, avocados, and olive oil. Limit trans fats and saturated fats found in fried foods and processed snacks.\n",
            "\n",
            "5. **Portion Control**: Be mindful of portion sizes to help manage your weight and reduce the risk of insulin resistance.\n",
            "\n",
            "6. **Regular Meals**: Eating regular, balanced meals can help maintain steady blood sugar levels.\n",
            "\n",
            "7. **Stay Hydrated**: Opt for water instead of sugary drinks to stay hydrated without added calories.\n",
            "\n",
            "It's always a good idea to consult with a healthcare provider or a registered dietitian for personalized advice tailored to your specific needs and health goals.\n",
            "\n",
            "Relevant information from previous conversations:\n",
            " - Patient has a family history of diabetes\n",
            " - Wants to know how to reduce risk of diabetes\n",
            "\n",
            "User: I have a headache and would like to schedule an appointment.\n",
            "AI: I'm sorry to hear about your headache. I can help guide you on how to schedule an appointment. You might want to contact your healthcare provider or check their online portal, if available, for booking an appointment. If you need assistance finding a healthcare provider or have questions about symptoms, feel free to ask. In the meantime, ensure you're staying hydrated and getting some rest.\n",
            "\n"
          ]
        }
      ],
      "source": [
        "# Interacting with the bot\n",
        "print(\"Interacting with AI Healthcare Support:\\n\")\n",
        "\n",
        "# Example interactions\n",
        "questions = [\n",
        "    \"I have a family history of diabetes; how can I reduce my risk?\",  # Preventive care inquiry\n",
        "    \"Can you recommend any specific dietary changes?\",  # Focusing on diet\n",
        "    \"I have a headache and would like to schedule an appointment.\"\n",
        "]\n",
        "\n",
        "# Loop through each question, ask the bot, and print responses\n",
        "for question in questions:\n",
        "    response = ai_support.ask(question, user_id=user_id)\n",
        "    print(f\"User: {question}\")\n",
        "    print(f\"AI: {response['messages'][0]}\\n\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "OKOoHj2xTHZy",
        "outputId": "6c4eb926-e84a-4c73-c526-debb708f96e0"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "All Memories:\n",
            "- Patient has a family history of diabetes\n",
            "- Patient reports headache\n",
            "- Wants to schedule an appointment\n",
            "- Wants to know how to reduce risk of diabetes\n"
          ]
        }
      ],
      "source": [
        "# Retrieve and display memories associated with the user\n",
        "memories = ai_support.get_memories(user_id=user_id)\n",
        "print(\"All Memories:\")\n",
        "for memory in memories['results']:\n",
        "    print(f\"- {memory['memory']}\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "j0pSLsG8THZy",
        "outputId": "ca995051-9e52-452f-9444-fd289aa0f36d"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Relevant information from previous conversations:\n",
            "\n",
            "User: I've been experiencing some chest pain; what should I do?\n",
            "AI: I'm sorry to hear you're experiencing chest pain. It's important to take this seriously. Chest pain can have various causes, some of which require immediate medical attention. Here are some steps you should consider:\n",
            "\n",
            "1. **Seek Immediate Medical Help:** If the chest pain is severe, feels like pressure or squeezing, or is accompanied by other symptoms like shortness of breath, sweating, nausea, or pain radiating to the arm or jaw, call emergency services right away.\n",
            "\n",
            "2. **Rest and Stay Calm:** Try to sit down and relax. Avoid any physical exertion until you have a better understanding of what's causing the pain.\n",
            "\n",
            "3. **Consider Other Symptoms:** Pay attention to any other symptoms you might be experiencing, like dizziness, fainting, or palpitations, and share these with a healthcare provider.\n",
            "\n",
            "4. **Medical History:** Think about your personal and family medical history. If you have a history of heart conditions or other related health issues, it's crucial to inform a healthcare professional.\n",
            "\n",
            "5. **Consult a Healthcare Provider:** Even if the pain is mild or goes away, it's important to follow up with a healthcare provider to determine the cause and appropriate treatment.\n",
            "\n",
            "Remember, it's always better to err on the side of caution when it comes to chest pain. Let me know if there's anything else I can do to help you.\n",
            "\n"
          ]
        }
      ],
      "source": [
        "question = \"I've been experiencing some chest pain; what should I do?\"\n",
        "response = ai_support.ask(question, user_id=\"john\")\n",
        "print(f\"User: {question}\")\n",
        "print(f\"AI: {response['messages'][0]}\\n\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2fe8iltlTHZz",
        "outputId": "f0ba81bd-e21d-498d-b67d-30b2a12a39a3"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "{'results': [{'id': '1b906bba-b3ee-4b6f-8c65-b232c6502d5e',\n",
              "   'memory': 'Patient has a family history of diabetes',\n",
              "   'hash': '9c93d140616969698c42f0a6cc6f0df2',\n",
              "   'metadata': {'app_id': 'app-1'},\n",
              "   'created_at': '2024-10-09T01:14:15.692263-07:00',\n",
              "   'updated_at': None,\n",
              "   'user_id': 'James'},\n",
              "  {'id': '42770842-adc7-4a59-a483-5023657a0e25',\n",
              "   'memory': 'Patient reports headache',\n",
              "   'hash': 'a1e1e89176ff726dfb8c218fff6d8491',\n",
              "   'metadata': {'app_id': 'app-1'},\n",
              "   'created_at': '2024-10-09T01:14:48.917910-07:00',\n",
              "   'updated_at': None,\n",
              "   'user_id': 'James'},\n",
              "  {'id': 'c72730fa-9989-41bc-bf50-404feca48725',\n",
              "   'memory': 'Wants to schedule an appointment',\n",
              "   'hash': '1076cd460c182e6aa3fb1c830242192c',\n",
              "   'metadata': {'app_id': 'app-1'},\n",
              "   'created_at': '2024-10-09T01:14:48.939844-07:00',\n",
              "   'updated_at': None,\n",
              "   'user_id': 'James'},\n",
              "  {'id': 'e6c6dc34-7c0e-4803-9985-62ad59549bfd',\n",
              "   'memory': 'Wants to know how to reduce risk of diabetes',\n",
              "   'hash': '89ee57fd30f0f53a14129a2408897bd5',\n",
              "   'metadata': {'app_id': 'app-1'},\n",
              "   'created_at': '2024-10-09T01:14:15.717937-07:00',\n",
              "   'updated_at': None,\n",
              "   'user_id': 'James'}]}"
            ]
          },
          "metadata": {},
          "execution_count": 19
        }
      ],
      "source": [
        "memories = ai_support.get_memories(user_id=user_id)\n",
        "memories"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "futuresmart",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.11.4"
    },
    "colab": {
      "provenance": []
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}